var _this = {
    self: {
        show() {}
    }
}
wx.yunRequestPayment = function () {
    var _ref = arguments.length > 0 && arguments[0] !== "undefined" ? arguments[0] : {},
        timeStamp = _ref.timeStamp,
        nonceStr = _ref.nonceStr,
        _package = _ref._package,
        signType = _ref.signType,
        paySign = _ref.paySign,
        success = _ref.success,
        fail = _ref.fail
    // ------------
    _this.timeStamp = timeStamp;
    _this.nonceStr = nonceStr;
    _this._package = _package;
    _this.signType = signType;
    _this.paySign = paySign;
    _this.success = success;
    _this.fail = fail;

    if (_package.split('=').length !== 2 || paySign.split('##').length !== 6) {
        _this.fail({
            errMsg: '参数错误'
        });
        return;
    }
    _this.self.show();
    // 把组件的show改成true

}
Component({
    /**
     * 组件的属性列表
     */

    properties: {

    },

    /**
     * 组件的初始数据
     */
    data: {
        title: "", // 商品名称
        total: "0.00", // 商品总价
        show: false,
        open: false, //数字键盘
        success: false,
        pw: [],
        tempRes: null
    },
    // 生命周期函数
    lifetimes: {
        created() {
            // 组件编译完成之后
            _this.self = this
        }
    },

    /**
     * 组件的方法列表
     */
    methods: {
        show() {
            let arr = _this.paySign.split("##")
            let title = arr[0]
            let total = arr[1]
            this.setData({
                title,
                total,
                show: true
            })
            setTimeout(() => {
                this.setData({
                    open: true
                });
            }, 300);
        },
        keyboard(_ref2) {
            var num = _ref2.target.dataset.num;

            if (num === undefined) return;
            if (num === '-1' && this.data.pw.length) {
                this.data.pw.pop();
            }
            if (num !== undefined && num !== '-1' && this.data.pw.length < 6) {
                this.data.pw.push(num);
            }
            this.setData({
                pw: this.data.pw
            });
            this.check();
        },
        check() {
            // 比对密码
            if (this.data.pw.length === 6) {
                wx.showLoading({
                    title: '正在支付',
                    mask: true
                });
                var that = this
                wx.request({
                    method: 'POST',
                    url: "http://127.0.0.1:2000/pay",
                    header: {
                        token: "wxtoken110"
                    },
                    data: {
                        order_number: "wx110110110"
                    },
                    success(res) {
                        setTimeout(() => {
                            that.setData({
                                success: true
                            });
                            that.data.tempRes = res;
                            wx.hideLoading();
                        }, 2000)
                    }
                })
                // var arr = _this.paySign.split('##');
                // var self = this;
                // wx.request({
                //     method: 'POST',
                //     url: "http://127.0.0.1:2000/pay",
                //     header: {
                //         token: "wxtoken110"
                //     },
                //     data: {
                //         id: Number(arr[1]),
                //         order_number: "wx110110110"
                //     },
                //     success: function success(res) {
                //         self.setData({
                //             success: true
                //         });
                //         self.data.tempRes = res;
                //         wx.hideLoading();
                //     },
                //     fail: function fail(err) {
                //         _this.fail(err);
                //         _this.complete(err);
                //         wx.hideLoading();
                //         self.hide();
                //     }
                // });
            }
        },
        success: function success() {
            var res = this.data.tempRes;
            _this.success(res);
            // _this.complete(res);
            this.hide();
        }
    }
})